home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / PrinterStateReasons.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  91 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cups
  5. import statereason
  6. from timedops import TimedOperation
  7. from base import *
  8.  
  9. class PrinterStateReasons(Question):
  10.     
  11.     def __init__(self, troubleshooter):
  12.         Question.__init__(self, troubleshooter, 'Printer state reasons')
  13.         page = self.initial_vbox(_('Status Messages'), _('There are status messages associated with this queue.'))
  14.         self.label = gtk.Label()
  15.         self.label.set_alignment(0, 0)
  16.         self.label.set_line_wrap(True)
  17.         page.pack_start(self.label, False, False, 0)
  18.         troubleshooter.new_page(page, self)
  19.  
  20.     
  21.     def display(self):
  22.         troubleshooter = self.troubleshooter
  23.         
  24.         try:
  25.             queue = troubleshooter.answers['cups_queue']
  26.         except KeyError:
  27.             return False
  28.  
  29.         parent = self.troubleshooter.get_window()
  30.         cups.setServer('')
  31.         self.op = TimedOperation(cups.Connection, parent = parent)
  32.         c = self.op.run()
  33.         self.op = TimedOperation(c.getPrinterAttributes, args = (queue,), parent = parent)
  34.         dict = self.op.run()
  35.         text = ''
  36.         state_message = dict['printer-state-message']
  37.         if state_message:
  38.             text += _("The printer's state message is: '%s'.") % state_message
  39.             text += '\n\n'
  40.         
  41.         state_reasons_list = dict['printer-state-reasons']
  42.         if type(state_reasons_list) == unicode:
  43.             state_reasons_list = [
  44.                 state_reasons_list]
  45.         
  46.         self.state_message = state_message
  47.         self.state_reasons = state_reasons_list
  48.         human_readable_errors = []
  49.         human_readable_warnings = []
  50.         for reason in state_reasons_list:
  51.             if reason == 'none':
  52.                 continue
  53.             
  54.             r = statereason.StateReason(queue, reason)
  55.             (title, description) = r.get_description()
  56.             level = r.get_level()
  57.             if level == statereason.StateReason.ERROR:
  58.                 human_readable_errors.append(description)
  59.                 continue
  60.             if level == statereason.StateReason.WARNING:
  61.                 human_readable_warnings.append(description)
  62.                 continue
  63.         
  64.         if human_readable_errors:
  65.             text += _('Errors are listed below:') + '\n'
  66.             text += reduce((lambda x, y: x + '\n' + y), human_readable_errors)
  67.             text += '\n\n'
  68.         
  69.         if human_readable_warnings:
  70.             text += _('Warnings are listed below:') + '\n'
  71.             text += reduce((lambda x, y: x + '\n' + y), human_readable_warnings)
  72.         
  73.         self.label.set_text(text)
  74.         if state_message == '' and len(human_readable_errors) == 0 and len(human_readable_warnings) == 0:
  75.             return False
  76.         return True
  77.  
  78.     
  79.     def collect_answer(self):
  80.         if not self.displayed:
  81.             return { }
  82.         return {
  83.             'printer-state-message': self.state_message,
  84.             'printer-state-reasons': self.state_reasons }
  85.  
  86.     
  87.     def cancel_operation(self):
  88.         self.op.cancel()
  89.  
  90.  
  91.